package com.zwan.oam_rtc.runner;

import com.zwan.oam_rtc.bean.JimpSettings;
import com.zwan.oam_rtc.imps.JavaImp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 服务启动执行
 *
 * @author
 */
@Component
@Slf4j
@Order(value=1)

/*
 * Spring Boot应用程序在启动后，会遍历CommandLineRunner接口的实例并运行它们的run方法。
 * 也可以利用@Order注解（或者实现Order接口）来规定所有CommandLineRunner实例的运行顺序。
 */
public class Runner implements CommandLineRunner {

    protected ExecutorService executors = Executors.newCachedThreadPool();

    public JavaImp jimp;

    @Autowired
    JimpSettings jimpSettings;


    @Override
    public void run(String... args) throws Exception {

        log.info(">>>>>>>>>>>>>>>create imp begin<<<<<<<<<<<<<");

        jimp = new JavaImp();
        try {
            jimp.init("JImp", jimpSettings);
            jimp.setExecutors(executors);//在这之前jimp中是有excutor的，并且在jimp.init中还启动了线程
            executors.submit(jimp);
        } catch (Exception e) {
            log.info(e.getMessage());
        }
        log.info(">>>>>>>>>>>>>>>create imp end<<<<<<<<<<<<<");


    }

}


